define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pt/duty_list/index' + location.search,
                    add_url: 'pt/duty_list/add',
                    edit_url: 'pt/duty_list/edit',
                    del_url: 'pt/duty_list/del',
                    multi_url: 'pt/duty_list/multi',
                    import_url: 'pt/duty_list/import',
                    table: 'pt_duty_list',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'pt_person_id', title: __('Pt_person_id')},
                        {field: 'date_id', title: __('Date_id')},
                        {field: 'pt_depart_id', title: __('Pt_depart_id')},
                        {field: 'depart_name', title: __('Depart_name'), operate: 'LIKE'},
                        {field: 'pt_job_id', title: __('Pt_job_id')},
                        {field: 'job_name', title: __('Job_name'), operate: 'LIKE'},
                        {field: 'is_road', title: __('Is_road'), operate: 'LIKE'},
                        {field: 'road_fee', title: __('Road_fee'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        work: function () {
            // 初始化表格参数配置
            var ids = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);
            Table.api.init({
                extend: {
                    index_url: 'pt/duty_list/work/ids/'+ ids + location.search,
                    add_url: 'pt/duty_list/workadd/ids/' + ids,
                    edit_url: 'pt/duty_list/edit',
                    del_url: 'pt/duty_list/del',
                    multi_url: 'pt/duty_list/multi',
                    import_url: 'pt/duty_list/import',
                    table: 'pt_duty_list',
                }
            });
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'date', title: __('Date_id')},
                        {field: 'person.user_name', title: __('姓名')},
                        {field: 'depart.name', title: __('Pt_depart_id')},
                        // {field: 'depart_name', title: __('Depart_name'), operate: 'LIKE'},
                        {field: 'job.name', title: __('Pt_job_id')},
                        {field: 'road_image', title: __('路费附件'),events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'job_name', title: __('Job_name'), operate: 'LIKE'},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {
                          field: 'operate', 
                          title: __('Operate'), 
                          table: table, 
                          events: Table.api.events.operate, 
                          buttons: [
                              {
                                  name: 'clock',
                                  text: __('打卡管理'),
                                  icon: 'fa',
                                  classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                  url: function (row) {
                                      return Fast.api.fixurl('pt/duty_list/clock/dutyid/' + row.id)
                                  },
                              },
                          ],

                          formatter: Table.api.formatter.operate

                        }
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                commonSearch: false,
                search: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        clock: function () {
            // 初始化表格参数配置
            var dutyId = $('#duty_id').val();
            Table.api.init({
                extend: {
                    index_url: 'pt/duty_list/clock/dutyid/'+ dutyId + location.search,
                    add_url: 'pt/duty_list/clockAdd/dutyid/' + dutyId,
                    // edit_url: 'pt/duty_list/edit',
                    del_url: 'pt/duty_list/clockDel/dutyid/' + dutyId,
                    multi_url: 'pt/duty_list/multi',
                    import_url: 'pt/duty_list/import',
                    table: 'pt_duty_list',
                }
            });
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), visible: false},
                        {field: 'clock', title: __('打卡记录')},
                        {field: 'note', title: __('备注')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                commonSearch: false,
                search: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        workadd: function () {
            Controller.api.bindevent();
        },
        clockadd: function () {
            Controller.api.bindevent();
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
